<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" th:href="@{/layui/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/css/layuimini.css?v=2.0.4.2}" media="all">
    <link rel="stylesheet" th:href="@{/css/themes/default.css}" media="all">
    <link rel="stylesheet" th:href="@{/lib/fontawesome-free-5.15.4-web}" media="all">
    <style>
        body {
            padding: 20px;
        }
    </style>
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <label class="layui-form-label">EmpName</label>
        <div class="layui-input-block">
            <input type="text" name="name" required lay-verify="required" placeholder="Please input emp name" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">Gender</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" value="M" title="Man">
            <input type="radio" name="sex" value="F" title="Woman" checked>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">Age</label>
        <div class="layui-input-block">
            <input type="text" name="age" required lay-verify="required|number" placeholder="Please input age" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">Salary</label>
        <div class="layui-input-block">
            <input type="text" name="sal" required lay-verify="required|number" placeholder="Please input salary" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">Birthday</label>
        <div class="layui-input-block">
            <input type="text" name="birthday" required lay-verify="required" placeholder="Please input birthday" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">Department</label>
        <div class="layui-input-block">
            <select name="deptId" lay-verify="required">
                <option value="">Please select</option>
                <option th:each="dept:${deptList}" th:value="${dept.deptId}">
                    <span th:text="${dept.deptName}"></span>
                </option>
            </select>
        </div>
    </div>
    <div class="layui-form-item layui-form-text">
        <label class="layui-form-label">Home Address</label>
        <div class="layui-input-block">
            <textarea name="address" placeholder="Please input home address" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button id="btn-submit" class="layui-btn" lay-submit lay-filter="btn-submit-filter">Submit</button>
            <button type="reset" class="layui-btn layui-btn-primary">Reset</button>
        </div>
    </div>
</form>
<script th:src="@{/layui/layui.js}" charset="utf-8"></script>
<script th:inline="javascript">
    var ctxPath = [[@{/}]];
        layui.use(['laydate','table','form'],function () {
            var laydate = layui.laydate;
            var table = layui.table;
            var form = layui.form;
            var $ = layui.$;

            laydate.render({
                elem: '[name="birthday"]'

        });

            form.on('submit(btn-submit-filter)',function (data) {
                $("#btn-submit").attr("disabled","disabled").addClass("layui-btn-disabled");

                var url = ctxPath + "emp";
                $.post(url,data.field,function (response) {
                    if (response.code == 0){
                    layer.msg(response.message,{
                        icon: 1,
                        time: 2000
                    },function () {
                        parent.refreshTable();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    });
                    }else {
                        $("#btn-submit").removeAttr("disabled","disabled").removeClass("layui-btn-disabled");
                        layer.msg("Add Failure,please contact administrator",{
                            icon: 2,
                            anim: 6
                        });
                    }
                });
                return false;
                });
            });
</script>
</body>
</html>